#include <stdexcept>
#include <windows.h>
#include <judge.h>
#include "exception.hpp"

namespace judge {

judge_exception::judge_exception(jstatus_t status)
	: status_(status)
{}

jstatus_t judge_exception::status() const
{
	return status_;
}

win32_exception::win32_exception(DWORD error_code)
	: judge_exception(_error_code_to_jstatus(error_code))
{}

jstatus_t win32_exception::_error_code_to_jstatus(DWORD error_code)
{
	switch (error_code) {
	case ERROR_LOGON_FAILURE:
	case ERROR_ACCOUNT_RESTRICTION:
	case ERROR_INVALID_LOGON_HOURS:
	case ERROR_INVALID_WORKSTATION:
	case ERROR_PASSWORD_EXPIRED:
	case ERROR_ACCOUNT_DISABLED:
	case ERROR_PASSWORD_MUST_CHANGE:
		return JSTATUS_LOGON_FAILURE;
	case ERROR_PRIVILEGE_NOT_HELD:
		return JSTATUS_PRIVILEGE_NOT_HELD;
	default:
		return JSTATUS_GENERIC_ERROR;
	}
}

DWORD win32_exception::error_code() const
{
	return error_code_;
}

}